package com.dnndo.web.controller.system;

import com.dnndo.common.core.controller.BaseController;
import com.dnndo.common.core.domain.R;
import com.dnndo.common.core.domain.entity.SysDictData;
import com.dnndo.common.utils.StringUtils;
import com.dnndo.common.utils.bean.BeanDtoVoUtil;
import com.dnndo.system.domain.vo.SysDictDataVO;
import com.dnndo.system.service.ISysDictDataService;
import com.dnndo.system.service.ISysDictTypeService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据字典信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController
{
    @Autowired
    private ISysDictDataService dictDataService;

    @Autowired
    private ISysDictTypeService dictTypeService;


    /**
     * 根据字典类型查询字典数据信息
     */
    @GetMapping(value = "/type/{dictType}")
    public R<List<SysDictDataVO>> dictType(@PathVariable @ApiParam(value = "字典类型", required = true) String dictType)
    {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data))
        {
            data = new ArrayList<SysDictData>();
        }
        return R.ok(BeanDtoVoUtil.listVo(data, SysDictDataVO.class));
    }

//    /**
//     * 新增字典类型
//     */
//    @PreAuthorize("@ss.hasPermi('system:dict:add')")
//    @Log(title = "字典数据", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@Validated @RequestBody SysDictData dict)
//    {
//        dict.setCreateBy(getUsername());
//        return toAjax(dictDataService.insertDictData(dict));
//    }
//
//    /**
//     * 修改保存字典类型
//     */
//    @PreAuthorize("@ss.hasPermi('system:dict:edit')")
//    @Log(title = "字典数据", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@Validated @RequestBody SysDictData dict)
//    {
//        dict.setUpdateBy(getUsername());
//        return toAjax(dictDataService.updateDictData(dict));
//    }
//
//    /**
//     * 删除字典类型
//     */
//    @PreAuthorize("@ss.hasPermi('system:dict:remove')")
//    @Log(title = "字典类型", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{dictCodes}")
//    public AjaxResult remove(@PathVariable Long[] dictCodes)
//    {
//        dictDataService.deleteDictDataByIds(dictCodes);
//        return success();
//    }
}
